package com.youlai.boot.system.controller;

import com.youlai.boot.system.service.SupplyChainReportService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.system.model.form.SupplyChainReportForm;
import com.youlai.boot.system.model.query.SupplyChainReportQuery;
import com.youlai.boot.system.model.vo.SupplyChainReportVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 供应链日报前端控制层
 *
 * @author xiheforever
 * @since 2025-06-01 23:18
 */
@Tag(name = "供应链日报接口")
@RestController
@RequestMapping("/api/v1/supply-chain-report")
@RequiredArgsConstructor
public class SupplyChainReportController  {

    private final SupplyChainReportService supplyChainReportService;

    @Operation(summary = "供应链日报分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('system:supply-chain-report:query')")
    public PageResult<SupplyChainReportVO> getSupplyChainReportPage(SupplyChainReportQuery queryParams ) {
        IPage<SupplyChainReportVO> result = supplyChainReportService.getSupplyChainReportPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增供应链日报")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('system:supply-chain-report:add')")
    public Result<Void> saveSupplyChainReport(@RequestBody @Valid SupplyChainReportForm formData ) {
        boolean result = supplyChainReportService.saveSupplyChainReport(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取供应链日报表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('system:supply-chain-report:edit')")
    public Result<SupplyChainReportForm> getSupplyChainReportForm(
            @Parameter(description = "供应链日报ID") @PathVariable Long id
    ) {
        SupplyChainReportForm formData = supplyChainReportService.getSupplyChainReportFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改供应链日报")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('system:supply-chain-report:edit')")
    public Result<Void> updateSupplyChainReport(
            @Parameter(description = "供应链日报ID") @PathVariable Long id,
            @RequestBody @Validated SupplyChainReportForm formData
    ) {
        boolean result = supplyChainReportService.updateSupplyChainReport(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除供应链日报")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('system:supply-chain-report:delete')")
    public Result<Void> deleteSupplyChainReports(
            @Parameter(description = "供应链日报ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = supplyChainReportService.deleteSupplyChainReports(ids);
        return Result.judge(result);
    }
}
